<?php
/* SVN FILE: $Id: tags_controller.php 639 2008-03-20 02:04:17Z burzum $ */
/**
 * Short description for file.
 *
 * Long description for file
 *
 * PHP versions 4 and 5
 *
 * Cake Bakery
 *
 * Copyright (c) 2006,	Cake Software Foundation, Inc.
 * 							1785 E. Sahara Avenue, Suite 490-204
 * 							Las Vegas, Nevada 89104
 *
 * Licensed under the CAKE SOFTWARE FOUNDATION LICENSE(CSFL) version 1.0
 * Redistributions of files must retain the above copyright notice.
 * You may not use this file except in compliance with the License.
 *
 * You may obtain a copy of the License at:
 * License page: http://www.cakefoundation.org/licenses/csfl/
 * Copyright page: http://www.cakefoundation.org/copyright/
 *
 * @filesource
 * @copyright		Copyright (c) 2006, Cake Software Foundation, Inc.
 * @link				http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
 * @package			bakery
 * @subpackage		bakery.controllers
 * @since			Bakery v 1.0.0.0
 * @version			$Revision: 639 $
 * @modifiedby		$LastChangedBy: burzum $
 * @lastmodified	$Date: 2008-03-20 11:04:17 +0900 (木, 20 3 2008) $
 * @license			http://www.cakefoundation.org/licenses/csfl/  The CSFL License
 */
/**
 * Short description for file.
 *
 * Long description for file
 *
 * @package		bakery
 * @subpackage	bakery.controllers
 * @since		Bakery v 1.0.0.0
 *
 */
class TagsController extends AppController {
	var $name = 'Tags';
	
	var $paginate = array('limit' => '100');
     
	function index() {
		$this->Tag->recursive = 0;
		$this->set('tags', $this->paginate());
	}
	
	function popular() {    
		return $this->Tag->popular();
	}

	function admin_edit($id) {
		if(!empty($this->data)) {
			$this->cleanUpFields();
			if($this->Tag->save($this->data)) {
				$this->Session->setFlash(sprintf(__('The %s has been saved.', true), __('Tag',true)));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Please correct errors below.', true));
				$this->set('articles', $this->Tag->Article->generateList());
			}
		}
		$this->data = $this->Tag->read(null, $id);
		$this->set('articles', $this->Tag->Article->generateList());
	}

	function view($name) {
		$this->Tag->recursive = 2;
		$this->set('tag', $this->Tag->findByName($name));
	}

	function admin_index() {
		$this->index();
	}
	
	function admin_delete($id) {  
		$user = $this->_checkPerms();  
		if($perms['level'] === ADMIN) {
			if($this->Tag->del($id)) {
				$this->Session->setFlash(sprintf(__('The %s has been deleted.', true), __('Tag',true)));
				$this->redirect(array('controller' => 'tags', 'action' => 'index', 'admin' => true));
			}
		}
	}

}
?>